package com.tomtop.core.web.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.AsyncClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {
	
	@ConditionalOnBean(AsyncClientHttpRequestFactory.class)
	@Bean AsyncRestTemplate asyncRestTemplate(AsyncClientHttpRequestFactory clientHttpRequestFactory){
		return new AsyncRestTemplate(clientHttpRequestFactory); 
	}

	@ConditionalOnBean(ClientHttpRequestFactory.class)
	@Bean RestTemplate restTemplate(ClientHttpRequestFactory clientHttpRequestFactory) {
		return new RestTemplate(clientHttpRequestFactory);
	}
}
